package wxb.avalon.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import wxb.avalon.core.entity.Role;
import wxb.avalon.core.mapper.RoleMapper;
import wxb.avalon.core.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wxb
 * @since 2022-01-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Override
    public Integer getIdByName(String name) {
        LambdaQueryWrapper<Role> lq = Wrappers.lambdaQuery();
        lq.eq(Role::getName, name);
        return baseMapper.selectList(lq).stream().findFirst().orElseGet(Role::new).getId();
    }
}
